#!/usr/bin/python2.4
#
#Copyright 2009 Google Inc.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#

"""Unittest for admin_console module."""

import logging
import re
import unittest
from admin_console import AdminConsole


class Request(object):
  """Dummy Request class."""
  uri = ''


class Response(object):
  """Dummy Response class."""

  class Out(object):
    """Dummy Response class for Response object."""
    text = ''

    def write(self, st):
      """Dummy write response method.

      Args:
        st: String representing response html.
      """
      self.text = st
  out = Out()


class AdminConsoleTest(unittest.TestCase):
  """Tests for the class AdminConsole."""

  def setUp(self):
    logging.info('TEST: ' + self.id())

  def testGet(self):
    """Tests the GET method of the AdminConsole RequestHandler."""
    admin_console = AdminConsole()
    admin_console.request = Request()
    admin_console.response = Response()
    admin_console.request.uri = 'http://localhost:8080'
    admin_console.get()
    text = admin_console.response.out.text
    self.assert_(admin_console.response.out.text.startswith('<html>'))
    match = re.search(r'<title>Digital Content Wizard Admin Console</title>', text)
    self.assert_(match)
    match = re.search(r'<table class="admintable"', text)
    self.assert_(match)
    match = re.search(r'<span[^>]*>Version</span>', text)
    self.assert_(match)
    match = re.search(r'<span[^>]*>Preview</span>', text)
    self.assert_(match)
    match = re.search(r'<span[^>]*>Publish</span>', text)
    self.assert_(match)
    match = re.search(r'<span[^>]*>Delete</span>', text)
    self.assert_(match)


def main(unused_argv):
  unittest.main()
